create database DB3
use DB3
GO
create table UserApply
(
   Id  int  NOT NULL PRIMARY KEY identity,
   flag  int NOT NULL,
   destinct int  NOT NULL,
  
)
create table AcceptFlag(
Id int ,
flag nvarchar(20),
)
create trigger trg_UserApply
on UserApply
after insert
as
begin
	declare @flag int,@destinct int,@id int
	select @destinct=Id  from AcceptFlag where flag='已申请'
	select @id=id,@flag=flag from inserted
	if @flag =@destinct
		begin
		      update UserApply set flag=@flag where id=@id
		end
end
create table Aff(
id int,
accptFlag int,
overFlag int,
flag int
)
create table AccptFlag(
 id int ,
 flag nvarchar(20),
)
create proc proc_ProcessSomething
@id int 
as
begin
	declare @flag int,@overFlag int,@accptFlag int
	select @flag=id from AccptFlag where name = '已受理'
	select @overFlag =id from AccptFlag where name = '已过期'
	select @accptFlag  =id from AccptFlag where name = '已申请'
	update UserApply set flag=@flag where id=@id
	update UserApply set flag=@overFlag where flag=@acceptFlag and MeetDate<=now()
end